package com.example.mongodb.mongodb.controller.rabbitmq.toupic;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ReceiveLogTopic3 {

    private static final String EXCHANGE_NAME ="topic_logs";

    public static void main(String[] args) {

        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("123.207.179.78");
        connectionFactory.setPort(5672);
        connectionFactory.setVirtualHost("/");
        connectionFactory.setUsername("admin");
        connectionFactory.setPassword("admin");

        Connection connection = null;

        try {
            connection = connectionFactory.newConnection();
            Channel channel = connection.createChannel();


            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
            String queueName = channel.queueDeclare().getQueue();

            channel.queueBind(queueName, EXCHANGE_NAME,"lazy.#");
            DeliverCallback deliverCallback = (consumerTat,deliver)->{
              String message = new String(deliver.getBody());
                System.out.println("lazy.# 匹配到的消息是："+message);
            };


            channel.basicConsume(queueName,true,deliverCallback,consumerTat->{});

            

        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }





    }
}
